package com.scirillo.frases.preference;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;

public class FrasesPreferenceManager extends PreferenceActivity{

public static void SetAppContext(Context AppContext) { mAppContext  = AppContext; }
	
	private static Context mAppContext;
    public static String GetPTPreferences(String szKeyValue, String szDefaultValue)
    {
    	try 
    	{
    		SharedPreferences SPref = PreferenceManager.getDefaultSharedPreferences(mAppContext);
    		return SPref.getString(szKeyValue, szDefaultValue);
    	}
    	catch (ClassCastException e)
    	{
    		return "";
    	}    	
    }
    
    public static boolean GetPTPreferencesBool(String szKeyValue, boolean bDefaultValue)
    {
    	try 
    	{    		
    		SharedPreferences SPref = PreferenceManager.getDefaultSharedPreferences(mAppContext);
    		return SPref.getBoolean(szKeyValue, bDefaultValue);
    	}
    	catch (ClassCastException e)
    	{
    		return false;
    	}    	
    }
    
    
    public static int GetPTPreferencesInt(String szKeyValue, int nDefaultValue)
    {
    	try 
    	{    		
    		SharedPreferences SPref = PreferenceManager.getDefaultSharedPreferences(mAppContext);
    		return SPref.getInt(szKeyValue, nDefaultValue);
    	}
    	catch (ClassCastException e)
    	{
    		return 0;
    	}    	
    }
   
    
    public static void SetPTPreferences(String szKey, String szValue)
    {
    	try 
    	{    		
    		SharedPreferences SPref = PreferenceManager.getDefaultSharedPreferences(mAppContext);
    		SharedPreferences.Editor EditPref = SPref.edit();
    		EditPref.putString(szKey, szValue);
    		EditPref.commit();    		
    	}
    	catch (ClassCastException e)
    	{
    		return ;
    	}
    }
    
    public static void SetPTPreferences(String szKey, boolean bValue)
    {
    	try 
    	{    		
    		SharedPreferences SPref = PreferenceManager.getDefaultSharedPreferences(mAppContext);
    		SharedPreferences.Editor EditPref = SPref.edit();
    		EditPref.putBoolean(szKey, bValue);
    		EditPref.commit();    		
    	}
    	catch (ClassCastException e)
    	{
    		return ;
    	}
    }
    
    public static void SetPTPreferences(String szKey, int nValue)
    {
    	try 
    	{    		
    		SharedPreferences SPref = PreferenceManager.getDefaultSharedPreferences(mAppContext);
    		SharedPreferences.Editor EditPref = SPref.edit();
    		EditPref.putInt(szKey, nValue);
    		EditPref.commit();    		
    	}
    	catch (ClassCastException e)
    	{
    		return ;
    	}
    }

}
